package ThreadPoolDemo.bilibiliThread;

public class MultiThreadShareData {

	public static void main(String[] args) {
		ShareData1 data1 = new ShareData1();
		new Thread(new MyRunable1(data1)).start();
		new Thread(new MyRunable2(data1)).start();

		new Thread(new Runnable() {

			@Override
			public void run() {
				data1.decrement();

			}
		}).start();
		new Thread(new Runnable() {

			@Override
			public void run() {
				data1.increment();

			}
		}).start();
	}
}

class MyRunable1 implements Runnable {

	private ShareData1 data1;

	public MyRunable1(ShareData1 data1) {
		this.data1 = data1;
	}

	@Override
	public void run() {
		data1.increment();

	}

}

class MyRunable2 implements Runnable {

	private ShareData1 data1;

	public MyRunable2(ShareData1 data1) {
		this.data1 = data1;
	}

	@Override
	public void run() {
		data1.increment();

	}

}

class ShareData1/* implements Runnable */{
	private int count = 100;

	/*
	 * @Override public void run() { while (true) { count--;
	 * System.out.println(count); }
	 * 
	 * }
	 */

	private int j = 0;

	public void increment() {

		j++;
	}

	public void decrement() {
		j--;
	}

}
